#include <linux/stddef.h>
#include <linux/sched/prio.h>
#include <linux/cpumask.h>
#include <linux/sched/clock.h>

#include "_policy_/update_curr.c"

#include "_policy_/dl/deadline.c"
#include "_policy_/fair/fair.c"
#include "_policy_/rt/rt.c"
#include "_policy_/idle/idle.c"

#include "_policy_/pelt.c"

static const struct sched_class *sched_class_table[] = {
    &dl_sched_class,
    &rt_sched_class,
    &fair_sched_class,
    &idle_sched_class,

    NULL, /* __sched_class_lowest */
};

const struct sched_class **__sched_class_highest(void)
{
    return &sched_class_table[0];
}

const struct sched_class **__sched_class_lowest(void)
{
    return &sched_class_table[sizeof(sched_class_table) / sizeof(sched_class_table[0]) - 1];
}

const struct sched_class **__sched_class_at(const struct sched_class *sc)
{
    const struct sched_class **at = NULL;

    for (int i = 0; i < sizeof(sched_class_table) / sizeof(sched_class_table[0]); i++)
    {
        if (sched_class_table[i] == sc)
        {
            at = &sched_class_table[i];
            break;
        }
    }

    return at;
}

bool sched_class_above(const struct sched_class *a, const struct sched_class *b)
{
    const struct sched_class **s1, **s2;

    s1 = __sched_class_at(a);
    s2 = __sched_class_at(b);

    return (s1 < s2);
}

const struct sched_class *__setscheduler_class(int policy, int prio)
{
    if (dl_prio(prio))
        return &dl_sched_class;

    if (rt_prio(prio))
        return &rt_sched_class;

    return &fair_sched_class;
}
